package me.jiatao.kotlinmall.data.respository

import io.reactivex.Observable
import me.jiatao.baselibrary.data.net.RetrofitFactory
import me.jiatao.baselibrary.data.protocol.HttpResult
import me.jiatao.kotlinmall.data.api.HomeApi
import me.jiatao.kotlinmall.data.protocol.Article
import me.jiatao.kotlinmall.data.protocol.ArticleResponseBody
import me.jiatao.kotlinmall.data.protocol.Banner
import me.jiatao.usercenter.data.api.UserApi
import me.jiatao.usercenter.data.protocol.LoginReq
import me.jiatao.usercenter.data.protocol.RegisterReq
import me.jiatao.usercenter.data.protocol.UserInfo
import javax.inject.Inject

class HomeRepository @Inject constructor() {

    /**
     * 使用Retrofit2创建接口访问类
     */
    private val homeApi: HomeApi by lazy {
        RetrofitFactory.instance
            .create(HomeApi::class.java)
    }

    /**
     * 获取轮播图
     */
    fun getBanners(): Observable<HttpResult<List<Banner>>> {
        return homeApi.getBanners()
    }

    /**
     * 获取首页置顶文章列表
     */
    fun getTopArticles(): Observable<HttpResult<MutableList<Article>>> {
        return homeApi.getTopArticles()
    }

    /**
     * 获取文章列表
     */
    fun getArticles(pageNum: Int): Observable<HttpResult<ArticleResponseBody>> {
        return homeApi.getArticles(pageNum)
    }
}